#ifndef _COMMON_THREAD_H_
#define _COMMON_THREAD_H_

#include "sysdef.h"

#ifdef WIN32

#include <process.h>
#define THREAD_ID_TYPE        unsigned
#define THREAD_RETURN_TYPE    unsigned __stdcall

#else

#include <pthread.h>
#define THREAD_ID_TYPE        pthread_t
#define THREAD_RETURN_TYPE    void*

#endif

typedef THREAD_RETURN_TYPE update_thread_address(void* arg);

#define THREAD_HANDLE(function, param) THREAD_RETURN_TYPE function(void* param)

struct WorkThreadParam
{
    int   _index;
    void* _server;
};

class CThread
{
    CThread(const CThread &r);

    CThread& operator= (const CThread& r);

public:

    CThread();

    ~CThread();

    bool Start(update_thread_address* address, void* param, int stacksize = 1*1024*1024);

    void Stop();

private:

    THREAD_ID_TYPE m_id;
    
#ifdef WIN32
    HANDLE m_handle;
#endif

    update_thread_address* m_address;
};

#endif //_COMMON_THREAD_H_
